/*
 ============================================================================
 Name		: ListWidget.h
 Author	  : Zhang Jiawei
 Version	 : 1.0
 Copyright   : Your copyright notice
 Description : CListWidget declaration
 ============================================================================
 */

#ifndef MULTILINELISTWIDGET_H
#define MULTILINELISTWIDGET_H

// INCLUDES
#include "Control.h"
#include "Flickable.h"
#include "ScrollBar.h"
#include "MWidgetObserver.h"
#include <GDI.H>

// CLASS DECLARATION
class CMultilineWidgetItem : public CBase
{
public:
    enum TAlignment
    {
        EHLeft,
        EHRight,
        EHCenter
    };
    
    CMultilineWidgetItem();
    virtual ~CMultilineWidgetItem();
    
    void SetText(const TDesC& aText);
    void SetMultiLineText(const TDesC& aText);
    
    void SetColor(TRgb aColor);
    void SetAlignment(TAlignment aAlignment);
    
    const TDesC& GetText();
    TRgb GetColor() const;
    TAlignment GetAlignment() const;
    
    CDesCArray* GetTextArray();
    TBool CaluMultilineTextLine(TInt nWidth, CFont* pFont);
    
private:
    HBufC* 			m_pText;
    TRgb 			iColor;
    TAlignment 		iAlignment;
    CDesCArray*		iArray;
};

class CMultilineListWidget: public CControl, public MFlickableCallback, public MScrollBarObserver
{
public:
    ~CMultilineListWidget();
    static CMultilineListWidget* NewL(MWidgetObserver* aObserver = NULL);
    static CMultilineListWidget* NewLC(MWidgetObserver* aObserver = NULL);

protected:
    CMultilineListWidget();
    void ConstructL(MWidgetObserver* aObserver = NULL);
    
public:
    // form CControl
    virtual void Draw(CFbsBitGc& g);
    virtual TBool OnKeyDown(const TInt& keycode);
    virtual TBool OnMouseDown(const TPoint& aPt);
    virtual TBool OnMouseMove(const TPoint& aPt);
    virtual TBool OnMouseUp(const TPoint& aPt);
    virtual void FocusChanged(TBool aFocus, const TInt keyCode = 0);
    
    // from MFlickableCallback
    virtual TPoint ScrollOffset() const;
    virtual void SetScrollOffset(const TPoint& aOffset);
    
    // from MScrollBarObserver
    virtual void ChangeScrollPos(TInt nPos);
public:
    // new functions
    void SetRowCount(TInt aRowCount);
    TInt RowCount() const;
    void SetHighlightColor(TRgb aHighlightColor);
    TRgb HighlightColor() const;
    void Clear();
    void AddItem(CMultilineWidgetItem* item);
    const TDesC& GetCurrentItemText();
    void SetLoop(TBool aLoop);
    
    TBool CalcuItemArrayRect();
protected:
    virtual void SetFont(CFont* aFont);
	virtual void DrawItem(CFbsBitGc& g, CMultilineWidgetItem* aItem, TRect& aRect);
	virtual void SetScrollBar(TInt nPos, TInt nRange);

	virtual TInt CalcMaxRowWidth();
	virtual TInt CalcMaxRowHeight();

	CMultilineWidgetItem* GetItem(TInt aRow);
	
protected:
    MWidgetObserver* iObserver;
    RPointerArray<CMultilineWidgetItem> iItemArray;
    TInt iRowCount;
    TInt iMargin;
    CFont* iFont;
    TRgb iHighlightColor;
    
    CFlickable* iFlickable;
    TPoint iOffset;
    TInt iHeight;
    TInt iHighlight;
//    TInt iOrignHighlight;
    TInt iStartRow;
    TInt iEndRow;
    
    CScrollBar* iScrollBar;
    TBool	iShowScroll;
    TBool	iIsLoop;
    TInt	iItemHeight;
};

#endif // LISTWIDGET_H
